package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.UCommonUrls;
import com.ruoyi.system.service.IUCommonUrlsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 常用网址Controller
 * 
 * @author coco
 * @date 2024-06-04
 */
@Controller
@RequestMapping("/system/urls")
public class UCommonUrlsController extends BaseController
{
    private String prefix = "system/urls";

    @Autowired
    private IUCommonUrlsService uCommonUrlsService;

    @RequiresPermissions("system:urls:view")
    @GetMapping()
    public String urls()
    {
        return prefix + "/urls";
    }

    /**
     * 查询常用网址列表
     */
    @RequiresPermissions("system:urls:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UCommonUrls uCommonUrls)
    {
        startPage();
        List<UCommonUrls> list = uCommonUrlsService.selectUCommonUrlsList(uCommonUrls);
        return getDataTable(list);
    }

    /**
     * 导出常用网址列表
     */
    @RequiresPermissions("system:urls:export")
    @Log(title = "常用网址", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UCommonUrls uCommonUrls)
    {
        List<UCommonUrls> list = uCommonUrlsService.selectUCommonUrlsList(uCommonUrls);
        ExcelUtil<UCommonUrls> util = new ExcelUtil<UCommonUrls>(UCommonUrls.class);
        return util.exportExcel(list, "常用网址数据");
    }

    /**
     * 新增常用网址
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存常用网址
     */
    @RequiresPermissions("system:urls:add")
    @Log(title = "常用网址", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(UCommonUrls uCommonUrls)
    {
        return toAjax(uCommonUrlsService.insertUCommonUrls(uCommonUrls));
    }

    /**
     * 修改常用网址
     */
    @RequiresPermissions("system:urls:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        UCommonUrls uCommonUrls = uCommonUrlsService.selectUCommonUrlsById(id);
        mmap.put("uCommonUrls", uCommonUrls);
        return prefix + "/edit";
    }

    /**
     * 修改保存常用网址
     */
    @RequiresPermissions("system:urls:edit")
    @Log(title = "常用网址", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(UCommonUrls uCommonUrls)
    {
        return toAjax(uCommonUrlsService.updateUCommonUrls(uCommonUrls));
    }

    /**
     * 删除常用网址
     */
    @RequiresPermissions("system:urls:remove")
    @Log(title = "常用网址", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(uCommonUrlsService.deleteUCommonUrlsByIds(ids));
    }
}
